import jpype
import jpype.imports
from jpype.types import *
import os, json
import requests


class CallJava:
    def __init__(self):
        # java调用不可以加https://
        self.host = "117.141.2.214:44444"
        self.key = "20497666"
        self.secret = "QerqY5cOXHlwaRiAUQWT"
        self.jar = os.path.abspath("./artemis-http-client-1.1.3.jar")
    
    def call_java(self):
        jpype.startJVM(classpath=[self.jar])
        from com.hikvision.artemis.sdk import ArtemisHttpUtil
        from com.hikvision.artemis.sdk.config import ArtemisConfig

        jpype.java.lang.System.out.println("java_HelloWorld")

        ArtemisConfig.host = self.host
        ArtemisConfig.appKey = self.key
        ArtemisConfig.appSecret = self.secret
        
        # previewURLsApi = jpype.java.util.HashMap()
        # previewURLsApi.put("https://", "/artemis/api/video/v1/pictureInfos")
        previewURLsApi={"https://": "/artemis/api/video/v1/pictureInfos"}
        
        contentType = "application/json"
        
        jsonBody = {"pageNo": 1,
                    "pageSize": 400,
                    "startTime": "2020-07-26T15:00:00.000+08:00",
                    "endTime": "2021-07-26T15:00:00.000+08:00", }
        body = json.dumps(jsonBody)
        
        result = ArtemisHttpUtil.doPostStringArtemis(previewURLsApi, body, None, None, contentType, None)
        print(result)
        print("接口调用完毕")


if __name__ == '__main__':
    c = CallJava()
    c.call_java()
